﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace qw.Models
{
    //public class OpenLogin
    //{
    //    public string Id { get; set; } = Guid.NewGuid().ToString("N");
    //    [Display(Name = "接受")]
    //    public bool Accept { get; set; }
    //    [Display(Name = "默认年级")]
    //    public Grade DefaultGrade { get; set; }
    //    [Display(Name = "默认选课")]
    //    public List<OpenLoginCourse> OpenLoginCourses { get; set; }
    //}

    //public class OpenLoginCourse
    //{
    //    public string Id { get; set; } = Guid.NewGuid().ToString("N");

    //    [Display(Name = "课程")]
    //    public Course Course { get; set; }
    //    [Display(Name = "默认注册")]
    //    [Newtonsoft.Json.JsonIgnore]
    //    public OpenLogin OpenLogin { get; set; }
    //}
    //public class Grade
    //{
    //    public string Id { get; set; } = Guid.NewGuid().ToString("N");

    //    [Display(Name = "年级")]
    //    public string GradeName { get; set; }
    //    [Display(Name = "班级")]
    //    public string ClassName { get; set; }
    //    [Newtonsoft.Json.JsonIgnore]
    //    public List<Student> Students { get; set; }
    //}
    public partial class Course
    {
        public string Id { get; set; } = Guid.NewGuid().ToString("N");

        [Display(Name = "课程名称")]
        public string CourseName { get; set; }
        [Display(Name = "教师")]
        public string UserName { get; set; }
        [Display(Name = "门牌号")]
        public string Door { get; set; }
        [Newtonsoft.Json.JsonIgnore]
        public List<UserCourse> UserCourses { get; set; }
        [Newtonsoft.Json.JsonIgnore]
        public List<Chapter> Chapters { get; set; }
        [Newtonsoft.Json.JsonIgnore]
        public List<Lesson> Lessons { get; set; }
        public DateTime CreateTime { get; set; } = DateTime.Now;
        public string CreateBy { get; set; }
        public DateTime UpdateTime { get; set; } = DateTime.Now;
        public string UpdateBy { get; set; }
        public List<CourseFile> CourseFileses { get; set; }
    }

    public enum LessonState
    {
        正在上课,
        已经下课
    }

    public class Lesson
    {
        public string Id { get; set; } = Guid.NewGuid().ToString("N");
        [Display(Name = "章节")]
        public Chapter Chapter { get; set; }
        [Display(Name = "章节")]
        public String ChapterTitle => Chapter?.Title;
        [Display(Name = "课程")]
        public String CourseName => Course?.CourseName;
        [Display(Name = "上课时间")]
        public DateTime BeginTime { get; set; } = DateTime.Now;
        [Display(Name = "下课时间")]
        public DateTime? EndTime { get; set; }
        [Display(Name = "教师")]
        public string UserName { get; set; }

        [Display(Name = "状态")]
        public LessonState LessonState { get; set; }
        [Display(Name = "公开课")]
        public bool Public { get; set; } = true;
        [Display(Name = "广播弹幕")]
        public bool BroadcastDanmaku { get; set; } = true;
        [Display(Name = "允许匿名用户发送弹幕")]
        public bool AllowAnonymousDanmaku { get; set; } = true;
        [Display(Name = "课程")]
        public Course Course { get; set; }
        [Newtonsoft.Json.JsonIgnore]
        public List<Danmaku> Danmakus { get; set; }
        [Newtonsoft.Json.JsonIgnore]
        public List<Ask> Asks { get; set; }
        [Newtonsoft.Json.JsonIgnore]
        public List<StudentLesson> StudentLessons { get; set; }


    }

    public enum StudentLessonState
    {
        未到,
        上课,
        离开
    }
    public partial class StudentLesson
    {
        public string Id { get; set; } = Guid.NewGuid().ToString("N");
        [Display(Name = "进入时间")]
        public DateTime? EnterTime { get; set; }
        [Display(Name = "离开时间")]
        public DateTime? LeaveTime { get; set; }
        [Display(Name = "学生")]
        public string UserName { get; set; }
        [Display(Name = "学号/IP")]
        public string StudentNo { get; set; }
        [Display(Name = "连接Id")]
        public string ConnectionId { get; set; }
        public string Ip { get; set; }
        public StudentLessonState StudentLessonState { get; set; } = StudentLessonState.未到;
        [Display(Name = "上课课堂")]
        public Lesson Lesson { get; set; }
        public int DanmakuCount { get; set; }
        public int AnsweredCount { get; set; }
        public int NotAnsweredCount { get; set; }

    }

    public enum HomeWorkType
    {
        课程作业,
        章节作业,
        课后作业
    }
    public class HomeWork
    {
        public string Id { get; set; } = Guid.NewGuid().ToString("N");
        public HomeWorkType HomeWorkType { get; set; }
        public Course Course { get; set; }
    }

    public class HomeWorkStudent
    {
        public string Id { get; set; } = Guid.NewGuid().ToString("N");

    }

    public enum StudentCourseState
    {
        Apply,
        Accept,
        Reject
    }
    public class UserCourse
    {
        public string Id { get; set; } = Guid.NewGuid().ToString("N");
        [Display(Name = "学生")]
        public string UserName { get; set; }
        [Display(Name = "课程")]

        public Course Course { get; set; }
        [Display(Name = "学分")]
        public float Score { get; set; } = 1;
        [Display(Name = "选课状态")]
        public StudentCourseState StudentCourseState { get; set; }
    }

    public partial class Chapter
    {
        public string Id { get; set; } = Guid.NewGuid().ToString("N");
        [Display(Name = "课程")]
        public Course Course { get; set; }
        [Display(Name = "章节名称")]
        public string Title { get; set; }
        [Newtonsoft.Json.JsonIgnore]
        public List<Question> Questions { get; set; }
        [Display(Name = "教师")]
        public string UserName { get; set; }

        public string CreateBy { get; set; }
        public DateTime CreateTime { get; internal set; } = DateTime.Now;
        public string UpdateBy { get; internal set; }
        public DateTime UpdateTime { get; internal set; } = DateTime.Now;
        [Newtonsoft.Json.JsonIgnore]
        public List<Lesson> Lessons { get; set; }
        public List<ChapterFile> ChapterFiles { get; set; }

    }
    public class FileSaveInfo
    {
        public string Id { get; set; } = Guid.NewGuid().ToString("N");
        public FileMd5 FileMd5 { get; set; }
        public string CreateBy { get; set; }
        public DateTime CreateTime { get; internal set; } = DateTime.Now;
        public string FileName { get; set; }
    }
    public class CourseFile : FileSaveInfo
    {
        [Newtonsoft.Json.JsonIgnore]
        public Course Course { get; set; }
    }

    public class ChapterFile : FileSaveInfo
    {

        [Newtonsoft.Json.JsonIgnore]
        public Chapter Chapter { get; set; }

    }



    public class QuestionFile : FileSaveInfo
    {

        [Newtonsoft.Json.JsonIgnore]
        public Chapter Question { get; set; }
    }


    public partial class FileMd5
    {
        public string Id { get; set; } = Guid.NewGuid().ToString("N");

        public string Md5 { get; set; }
        public int FileLength { get; set; }
        public string Ext { get; set; }



    }

    public enum QuestionType
    {
        单选,
        多选,
        简答
    }
    public partial class Question
    {
        public string Id { get; set; } = Guid.NewGuid().ToString("N");
        [Display(Name = "问题类型")]
        public QuestionType Type { get; set; } = QuestionType.单选;
        [Display(Name = "标题")]
        public string Title { get; set; }
        [Display(Name = "图片")]
        public string ImgFileName { get; set; }
        [Display(Name = "内容")]
        public string Content { get; set; }
        [Display(Name = "Html文本")]
        public string HtmlText { get; set; }
        [Display(Name = "长文本")]
        public string OrText { get; set; }


        public Chapter Chapter { get; set; }

        [Display(Name = "总分")]
        public int TotalScore { get; set; } = 1;
        [Display(Name = "教师")]
        public string UserName { get; set; }
        public string OptionText { get; set; }

        public string[] QuestionOptions => OptionText?.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
        public DateTime CreateTime { get; set; } = DateTime.Now;
        public string CreateBy { get; set; }
        public DateTime UpdateTime { get; set; } = DateTime.Now;
        public string UpdateBy { get; set; }
    }

    //public class QuestionOption
    //{
    //    public string Id { get; set; } = Guid.NewGuid().ToString("N");

    //    [Display(Name = "标签")]
    //    public string Label { get; set; }
    //    [Display(Name = "内容")]
    //    public string Content { get; set; }
    //    public bool RightOption { get; set; }
    //    [Newtonsoft.Json.JsonIgnore]
    //    public Question Question { get; set; }
    //}

    public partial class Ask
    {
        public string Id { get; set; } = Guid.NewGuid().ToString("N");
        [Display(Name = "上课课堂")]
        public Lesson Lesson { get; set; }
        [Display(Name = "公共问题")]
        public bool Public { get; set; }
        [Display(Name = "问题")]
        public Question Question { get; set; }
        [Newtonsoft.Json.JsonIgnore]
        public List<Answer> Answers { get; set; }
        [Display(Name = "提问时间")]
        public DateTime BeginTime { get; set; } = DateTime.Now;
        [Display(Name = "结束时间")]
        public DateTime? EndTime { get; set; }
        [Display(Name = "教师")]
        public string UserName { get; set; }
        [Display(Name = "提问状态")]
        public AskState AskState { get; set; }
        public int? AnswerCount { get; set; }
        public int AnsweredCount { get; set; }

    }
    public enum AskState
    {
        Begin,
        End
    }
    public enum AnswerState
    {
        Answering,
        Answered,
        NotAnswered,
    }
    public partial class Answer
    {
        public string Id { get; set; } = Guid.NewGuid().ToString("N");
        [Display(Name = "学生")]
        public string UserName { get; set; }
        [Display(Name = "内容")]
        public string Data { get; set; }
        [Display(Name = "得分")]
        public float Score { get; set; }
        [Display(Name = "提问")]
        public Ask Ask { get; set; }
        [Display(Name = "回答时间")]
        public DateTime? AnswerTime { get; set; }
        [Display(Name = "上课时间")]
        public AnswerState AnswerState { get; set; }
        public string Ip { get; set; }
    }

    /// <summary>
    /// 弹幕
    /// </summary>
    public partial class Danmaku
    {
        [Display(Name = "上课课堂")]
        public Lesson Lesson { get; set; }
        public DateTime CreateTime { get; set; } = DateTime.Now;
        public string CreateBy { get; set; }
    }
}
